﻿namespace ICMRemoteEdu.Forms
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.IO;
    using System.Windows.Forms;

    public class ICMOpenCourseForm : Form
    {
        private string _courseDirectory = string.Empty;
        private string _courseFileName = string.Empty;
        private Button btnCancel;
        private Button btnOk;
        private Button btnShowOpenDialog;
        private IContainer components;
        private Label label1;
        private MaskedTextBox tbFileName;

        public ICMOpenCourseForm()
        {
            this.InitializeComponent();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
        }

        private void btnShowOpenDialog_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Title = "Выберите курс";
                dialog.CheckFileExists = true;
                dialog.Filter = "Файлы курсов|*.dat";
                dialog.Multiselect = false;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    this.tbFileName.Text = this.CourseFileName = dialog.FileName;
                    this.CourseDirectory = Path.GetDirectoryName(dialog.FileName);
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.label1 = new Label();
            this.tbFileName = new MaskedTextBox();
            this.btnShowOpenDialog = new Button();
            this.btnOk = new Button();
            this.btnCancel = new Button();
            base.SuspendLayout();
            this.label1.AutoSize = true;
            this.label1.Font = new Font("Tahoma", 11.25f, FontStyle.Regular, GraphicsUnit.Point, 0xcc);
            this.label1.Location = new Point(12, 9);
            this.label1.Name = "label1";
            this.label1.Size = new Size(110, 0x12);
            this.label1.TabIndex = 0;
            this.label1.Text = "Выберите курс";
            this.tbFileName.Location = new Point(13, 0x1f);
            this.tbFileName.Name = "tbFileName";
            this.tbFileName.ReadOnly = true;
            this.tbFileName.Size = new Size(0xeb, 20);
            this.tbFileName.TabIndex = 1;
            this.btnShowOpenDialog.Location = new Point(0xf8, 0x1d);
            this.btnShowOpenDialog.Name = "btnShowOpenDialog";
            this.btnShowOpenDialog.Size = new Size(0x18, 0x17);
            this.btnShowOpenDialog.TabIndex = 2;
            this.btnShowOpenDialog.Text = "...";
            this.btnShowOpenDialog.UseVisualStyleBackColor = true;
            this.btnShowOpenDialog.Click += new EventHandler(this.btnShowOpenDialog_Click);
            this.btnOk.DialogResult = DialogResult.OK;
            this.btnOk.Location = new Point(13, 0x3a);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new Size(0x4b, 0x17);
            this.btnOk.TabIndex = 3;
            this.btnOk.Text = "Ок";
            this.btnOk.UseVisualStyleBackColor = true;
            this.btnOk.Click += new EventHandler(this.btnOk_Click);
            this.btnCancel.DialogResult = DialogResult.Cancel;
            this.btnCancel.Location = new Point(0xc5, 0x3a);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x4b, 0x17);
            this.btnCancel.TabIndex = 4;
            this.btnCancel.Text = "Отмена";
            this.btnCancel.UseVisualStyleBackColor = true;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x11c, 0x5d);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnOk);
            base.Controls.Add(this.btnShowOpenDialog);
            base.Controls.Add(this.tbFileName);
            base.Controls.Add(this.label1);
            base.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "ICMOpenCourseForm";
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "Дистанционное обучение";
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        public string CourseDirectory
        {
            get
            {
                return this._courseDirectory;
            }
            set
            {
                if (!Directory.Exists(value))
                {
                    throw new DirectoryNotFoundException("Указанная папка не существует");
                }
                this._courseDirectory = value;
            }
        }

        public string CourseFileName
        {
            get
            {
                return this._courseFileName;
            }
            set
            {
                if (!File.Exists(value))
                {
                    throw new FileNotFoundException("Указанный файл не существует", value);
                }
                this._courseFileName = value;
            }
        }
    }
}

